<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    姓 : <input type="text" v-model="firstName"> <br>
    名 : <input type="text" v-model="lastName">
    <br>
    <br>
    <br>
    <br>
    <input type="text" v-model="fullName">
</div>
</body>
<script src="../js/vue.js"></script>
<script>
    Vue.config.productionTip = false;

    new Vue({
        el:"#app",
        data:{
            firstName:"T",
            lastName:"Mac",
            fullName:""
        },
        //watch用来监听data中的数据
        watch:{
            firstName:{
                handler(newVal,oldVal){
                    console.log("firstName")
                    this.fullName = newVal + "-" + this.lastName
                },
                immediate:true  //初始化的时候会执行handler
            },
            lastName:{
                handler(newVal,oldVal){
                    console.log("lastName")
                    this.fullName =   this.firstName + "-" + newVal
                },
                immediate:true
            }
        }

        /*watch:{
            firstName(newVal,oldVal){
                console.log("firstName")
                this.fullName = newVal + "-" + this.lastName
            },
            lastName(newVal,oldVal){
                console.log("lastName")
                this.fullName =   this.firstName + "-" + newVal
            }
        }*/
    })
</script>
</html>